home *** CD-ROM | disk | FTP | other *** search
- Path: easy.in-chemnitz.de!mkmk!floh
- From: floh@mkmk.in-chemnitz.de (Andre Weissflog)
- Newsgroups: comp.sys.amiga.programmer,uiuc.class.cs110c,uiuc.class.cs223
- Subject: Re: How do I define my integers?
- Message-ID: <D33Xx*bB0@mkmk.in-chemnitz.de>
- Date: Sun, 14 Jan 1996 02:52:23 CET
- Reply-To: floh@mkmk.in-chemnitz.de
- References: <4d73ug$25v@vixen.cso.uiuc.edu>
- Distribution: world
- Organization: private uucp site
- X-Newsreader: Arn V 1.04
-
- In article <4d73ug$25v@vixen.cso.uiuc.edu>, howard daniel joseph writes:
-
- > Okay. I'm writing a program under GCC on my Amiga.
- >
- > But I'm confused to hell over integer limits.
- >
- > My book talks about 2 bit and 4 bit integers ... and four bit
- ^^^
- should be bytes
-
- > integers like what it describers long integers to be. Of course there's
- > unsigned integers and the like too.
- >
- The only rule about int types in C is IMHO that
-
- short <= int <= long
-
- meaning that "short" can hold a smaller or equal number range
- then "int" and the same for "int" versus "long".
-
- With most Amiga compilers, "short" holds 16 bit accuracy,
- "int" and "long" hold 32 bits. On the PC, older "16-bit compilers"
- have often 16 bit ints.
-
- The best solution is to consistently use the types defined in
- <exec/types.h>, called
-
- BYTE - signed (8-bit) byte
- UBYTE - unsigned (8-bit) byte
- WORD - the same for 16 bit
- UWORD
- LONG - the same for 32 bits
- ULONG
-
- > How do I declare signed versus unsigned integers?
- >
-
- With "raw ANSI"
-
- int a; - gives a signed variable (16 or 32 bits! compiler-dependent)
- unsigned int a; - the same for unsigned
-
- With Amiga conventions:
-
- ULONG a; - gives an unsigned 32 bit integer
- LONG a; - the same signed
-
- > How do I know how many bits my integers are using?
- >
- see above :-)
-
- > How do I declare signed and unsigned long integers?
- >
- see above
-
- > What's with these "doubles" the book mysteriously alludes to?
- >
- Floating point numbers. Only useful for number crunching IMHO.
-
- > What *am* I creating when I type;
- >
- > int somevalue;
- > (ie Is it signed/unsigned? How many bits?)
- >
- This is signed, it depends on your compiler, if it is 16 or 32 bits,
- usually it is 32 bits.
-
- > I know many of the answers here, but if I could get them all from one
- > source I'd feel a lot better.
- >
- > I need two sorts of values for my project;
- >
- > An integer (unsigned) that can handle, 6, though ideally 9 places (Just
- > under 250000000 would be the maximum forseen possible value here.)
- >
- 250,000,000 decimal would fit into an signed 32 bit integer
- (a "int" or a "long" in ANSI, or a "LONG" with Amiga conventions).
-
- > An integer that can handle a much bigger number ... 12 places at least for
- > now.
- >
- Aargh, no chance with 32 bit numbers. (2^32)-1 is 4,294,967,295,
- so no luck for you. Why in the world do you need such big numbers???
-
- > Can I perform simple maths (addition, division) between integers of
- > different types? I'd assume so, right?
- >
- Yes, the compiler will do what it can to ensure results that
- make sense. Be careful with unsigned numbers (they can't get
- smaller then 0).
-
- Bye,
- -Floh.
-
- ====//=== Andre Weissflog <floh@mkmk.in-chemnitz.de> =======
- ...// Sep'95: Return Of The Living Death...................
- \\// 90% of everything is crap (Sturgeon's Law)...........
- =\\===============================================Amiga!=
-
-